package guiCode;

import java.sql.SQLException;
import java.util.Vector;

import teacher.getSemester;

import com.sun.rowset.CachedRowSetImpl;

import basic.ClientConsole;
import flexibility.CachedRowSetTableModel;
import flexibility.userData;
import gui.TeacherMainMenuGUI;



public class TeacherMainMenuCode {
	public static int[] sem;
	public static Vector<Integer> semesters=new Vector<Integer>();
	public static Vector<Integer> courses=new Vector<Integer>();
	private userData T_Data = new userData();
	private static ClientConsole teacherConnection;
	private TeacherMainMenuGUI tmm ;
	private CachedRowSetImpl rs;
	private static Integer myID;
	private checkDataBase busy = new checkDataBase();
	
	public void setConnection(ClientConsole conn) {
		setTeacherConnection(conn);
		try {
			rs = new CachedRowSetImpl();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
		public void setMyID(int id) {
			myID = id;
		}
		public static Integer getMyID() {
			return myID;
		}
		
		public void getSemesters()
		{
			
			getSemester gs = new getSemester();
			rs=gs.getSemesters(getTeacherConnection(), rs, T_Data,myID);
			tmm.getPanel2().getComboBox().addItem("  ");
		try {
			while (rs.next())
			{
				tmm.getPanel2().getComboBox().addItem(rs.getString(1).substring(0, rs.getString(1).length()-2)+":"+rs.getString(2)+"   "+rs.getString(3)+rs.getString(4));	
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		}

		public void close() {
			T_Data.deleteAll();//updating database on user leaving the system
			T_Data.addData(7);
			T_Data.addData(0);
			T_Data.addData(myID);
			busy.setBusy(true);
			getTeacherConnection().acceptMsg(T_Data);
			getTeacherConnection().getResults();// waiting for database change to
			T_Data.deleteAll();
			T_Data.addData(-1);//closing the connection
			getTeacherConnection().acceptMsg(T_Data);
			// happen
			busy.setBusy(false);
			// TODO Auto-generated method stub
			
		}

		public static ClientConsole getTeacherConnection() {
			return teacherConnection;
		}

		public void setTeacherConnection(ClientConsole teacherConnection) {
			this.teacherConnection = teacherConnection;
		}

		
		 
}
